package com.example.docking.service.impl;

import com.example.docking.dao.jindie.ResponseData;
import com.example.docking.dao.jindie.request.MaterialDataRequest;
import com.example.docking.service.DataService;
import com.example.docking.util.Constants;
import com.google.gson.Gson;
import com.smecloud.apigw.model.ApiResult;

import java.util.HashMap;

public class DataServiceImpl extends BaseServiceImpl implements DataService {
    @Override
    public ApiResult SelectDataList(String path, HashMap<String, String> map, Object o) throws Exception {
        return sendApiRequestGet(path, map, o);
    }

    @Override
    public ApiResult InsertDataOne(String path, HashMap<String, String> map, Object materialData) throws Exception {
        return sendApiRequestPostBody(path, map, materialData);
    }

    @Override
    public ApiResult UpdateData(String path, HashMap<String, String> map, Object materialData) throws Exception {
        return sendApiRequestPostBody(path, map, materialData);
    }

    @Override
    public ApiResult DeleteData(String path, HashMap<String, String> map, MaterialDataRequest materialData) throws Exception {
        return sendApiRequestGet(path, map, materialData);
    }

    @Override
    public ApiResult SelectDataDetail(String path, HashMap<String, String> map, Object o) throws Exception {
        // map.put("id", "2177772470629580800");
        return sendApiRequestGet(path, map, o);
    }

    @Override
    public ApiResult SelectDataAudit(String path, HashMap<String, String> map, Object o) throws Exception {
        // map.put("id", "2177772470629580800");
        return sendApiRequestPostBody(path, map, o);
    }

    public ApiResult InsertDataPush(String path, HashMap<String, String> map, Object o) throws Exception {
        return sendApiRequestPostBody(path, map, o);
    }
//    public static void main(String[] args) throws Exception {
//        Gson gson = new Gson();
//        Type type = new TypeToken<ResponseData<GenericDataItem<MaterialData>>>() {
//        }.getType();
//        DataService materialService = new DataServiceImpl();
////        ApiResult result = materialService.productSelectList();
////        ResponseData<GenericDataItem<MaterialData>> response = gson.fromJson(result.getBody(), type);
////
//
//        MaterialDataRequest materialDataRequest = new MaterialDataRequest();
////        materialDataRequest.setId("2177772470629580800");
//        materialDataRequest.setBase_unit_id("2177772470629580800");
//

    /// /            materialDataRequest.setUnit_id("2177772470629580800");//计量单位
    /// /            materialDataRequest.setModel("自制件");//类别
//        materialDataRequest.setName("材料8");//商品名称
//        //        materialDataRequest.setNet_weight("100");//净重
//        //        materialDataRequest.setIs_self_restraint(true);//是否自制
//        //        materialDataRequest.setPurchase_unit_id("2177772470629580800");//采购单位
//        //        materialDataRequest.setSale_unit_id("4");//销售单位
//        //        materialDataRequest.setStore_unit_id("4");//库存单位
//        //        materialDataRequest.setAux_unit_id("4");//报表辅助ID
//        //        materialDataRequest.setParent_id("4");
//        //        materialDataRequest.setBase_unit_name("件");
//        //        materialDataRequest.setBase_unit_number("件");
//        HashMap<String, String> map = new HashMap<>();
//        map.put("page", "1");
//        map.put("page_size", "100");
//        ApiResult result1 = materialService.InsertDataOne(Constants.MATERIAL_PATH, map, materialDataRequest);
//        Type type1 = new TypeToken<ResponseData<SaveData>>() {
//        }.getType();
//        ResponseData<SaveData> response = gson.fromJson(result1.getBody(), type1);
//        System.out.println("Code: " + response.getErrcode());
//        System.out.println("Message: " + response.getDescription());
//        System.out.println("data: " + response.getData());
//    }
    public static void main(String[] args) throws Exception {
        Gson gson = new Gson();
        DataServiceImpl service = new DataServiceImpl();
        HashMap<String, String> map = new HashMap<>();
        map.put("page", "1");
        map.put("page_size", "100");
        map.put("search", "VS-1000-22");
//        String[] ids = new String[1];
//        ids[0] = "2194393640258794496";//2194393640258794496
        // 将数组转换为逗号分隔的字符串
//        String idsParam = String.join(",", ids);
//        map.put("ids", idsParam);
        ApiResult result = service.SelectDataList(Constants.MATERIAL_PATH, map, "");
//        map.put("id", "2200172263456686086");
//        ApiResult result = service.SelectDataDetail(Constants.MO_TASKBILL_DETAIL,map,"");
        ResponseData response = gson.fromJson(result.getBody(), ResponseData.class);
        System.out.println("Code: " + response.getErrcode());
        System.out.println("Message: " + response.getDescription());
        System.out.println("data: " + response.getData());

    }
}
